<!-- 菜单弹框 -->
<form id="menus-form" lay-filter="menus-form" class="layui-form model-form">
    <input name="id" type="hidden"/>
    <div class="layui-form-item">
        <label class="layui-form-label">批次名称</label>
        <div class="layui-input-block">
            <input id="batchName" name="batchName" placeholder="请输入批次名称" type="text" class="layui-input" maxlength="50"
                   lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">预付金额</label>
        <div class="layui-input-block">
            <input id="prePay" name="prePay" placeholder="请输入预付金额" type="text" class="layui-input"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">实付金额</label>
        <div class="layui-input-block">
            <input id="actuallyPay" name="actuallyPay" placeholder="请输入实付金额" type="text" class="layui-input"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">支付状态</label>
        <div class="layui-input-block">
            已支付 <input id="status1" name="payStatus" type="radio" class="layui-input" value="1"/>
            未支付 <input id="status2" name="payStatus" type="radio" class="layui-input" value="0"/>
        </div>
    </div>


    <div class="layui-form-item model-form-footer">
        <button class="layui-btn layui-btn-primary" ew-event="closeDialog" type="button">取消</button>
        <button type="button" class="layui-btn" lay-filter="menus-form-submit" lay-submit>保存</button>
    </div>
</form>

<script>
    layui.use(['layer', 'admin', 'form', 'formSelects'], function () {
        var layer = layui.layer;
        var admin = layui.admin;
        var form = layui.form;
        var formSelects = layui.formSelects;

        form.render('radio');

        //菜单渲染 把内容加载进去

        //获取工资记录
        let renderFormByBatchId = function () {
            let batchId = admin.getTempData('batchId');
            myJsonAjax("api-trade/concurrent/findSalaryByBatchId", batchId, "post", function (data) {
                let result = data.data;

                $("#batchName").val(result.batchName)
                $("#prePay").val(result.prePay)
                $("#actuallyPay").val(result.actuallyPay)
                if (result.payStatus === 1) {
                    $("input[type='radio']").eq(0).attr("checked", true)
                } else {
                    $("input[type='radio']").eq(1).attr("checked", true)
                }

                form.render();
            })
        }

        renderFormByBatchId();


        // 表单提交事件
        form.on('submit(menus-form-submit)', function (data) {
            let batchId = admin.getTempData('batchId');

            let params = {
                batchId: batchId,
                batchName: $("#batchName").val(),
                prePay: $("#prePay").val(),
                actuallyPay: $("#actuallyPay").val(),
                payStatus: $("input[type='radio']:checked").val()
            }

            myJsonAjax("api-trade/concurrent/editSalaryByBatchId", params, "post", function (result) {
                    layer.msg("修改成功",{icon:1,time:800},function (index) {
                        layer.closeAll();
                        window.parent.location.reload()
                    })
                })

        })


    });

    function myJsonAjax(url, data, type, callback) {
        let token = JSON.parse(layui.data('easyweb').token).access_token
        $.ajax({
            url: 'http://127.0.0.1:9200/' + url,
            data: JSON.stringify(data),
            dataType: "json",
            type: type,
            contentType: "application/json",
            beforeSend: function (xhr) {
                xhr.setRequestHeader('Authorization', 'Bearer ' + token);
            },
            success: callback
        })
    }
</script>